﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.8/angular.min.js"></script>
    <style type="text/css">
        #userenter textarea {
            width: 600px;
            height: 500px;
            margin-left: 20px;
        }

        #userenter li {
            height: 500px;
            width: 650px;
        }

        dd {
            word-wrap: break-word;
            word-break: normal;
        }
    </style>
</head>
<body>
    <div ng-controller="diskname" id="diskname" class="text-center text-primary">
        简介：网盘助手，输入文件地址，获取真实下载链接。程序源码：<a href="https://git.oschina.net/wangjunniit/NetworkDiskHelper" target="_blank">https://git.oschina.net/wangjunniit/NetworkDiskHelper</a>
        <ul class="list-inline">
            <li><h3>支持的网盘:</h3></li>
            <li ng-repeat="item in objJson">{{ item }}</li>
        </ul>
    </div>

    <ul class="list-inline" id="userenter">
        <li><textarea class="form-control" placeholder="输入地址，每行一个" id="userpost"></textarea></li>
        <li class="text-primary" style="overflow-y:scroll" ng-controller="downloadlinks" id="downloadlinks">
            <dl ng-repeat="item in links">
                <dt>原始地址 </dt>
                <dd>{{item.OriginalUrl}}</dd>
                <dt>下载地址</dt>
                <dd>{{item.DownloadUrl}}</dd>
            </dl>
        </li>
    </ul>

    <div style="text-align:center;">
        <input value="获取下载地址" type="button" id="postbtn" class="btn btn-large btn-primary" />
        <span id="msgspan" class="text-info"></span>
    </div>

    <script type="text/javascript">

        var app = angular.module('index', []);

        app.controller('diskname', function($scope) {
            $scope.objJson = @Html.Raw(ViewBag.diskName);
        });

        app.controller('downloadlinks',function($scope){
            $scope.links=[];
        });

        angular.bootstrap(document, ['index']);

        $(function(){

            function message(str){
                $("#msgspan").html(str);
            }

            $("#postbtn").on('click',function(){
                $.ajax({
                    url:"/api/NetworkDiskHelperApi/GetDownloadLink",
                    type:"post",
                    data:{userPost:$("#userpost").val()},
                    success:function(msg){

                        $("#downloadlinks").scope().links=msg;
                        $("#downloadlinks").scope().$apply();

                    },complete:function(){
                        $("#postbtn").removeAttr("disabled");
                        message("");
                    },
                    beforeSend:function(){
                        $("#postbtn").attr({"disabled":"disabled"});
                        message("正在获取数据……");
                    }
                });//endajax

            });//endclick

        });//endonload
    </script>
</body>
</html>
